package com.qf.ssm.controller;

import com.qf.ssm.dto.R;
import com.qf.ssm.pojo.Menu;
import com.qf.ssm.pojo.Menus;
import com.qf.ssm.service.MenuService;
import com.qf.ssm.service.MenusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/menus")
public class MenuController {

    private MenusService menusService;

    private MenuService menuService;

    @Autowired
    public void setMenuService(MenuService menuService) {
        this.menuService = menuService;
    }

    @Autowired
    public void setMenusService(MenusService menusService) {
        this.menusService = menusService;
    }

    @GetMapping("/menus")
    public R findAllMenus() {
        List<Menu> menusList = menusService.findAllLeftMenus();//获取到所有的菜单
        return R.setOK(menusList);
    }

    @PostMapping("/menu")
    public R addMenu(@RequestBody Menu menu){
        menuService.addMenu(menu);
        return R.setOK();
    }

    @PutMapping("/menu")
    public R updateMenu(@RequestBody Menu menu){
        menuService.updateMenu(menu);
        return R.setOK();
    }

    @DeleteMapping("/menus")
    public R deleteMenuByIds(Long []ids){
        menuService.deleteMenuByIds(ids);
        return R.setOK();
    }
}


